/* ------------------------------------------------------------------------*
 *
 * ------------------------------------------------------------------------*/
#include "gd25q_cmd.h"
#include "gd25q_hal.h"
#include "gd25q_manage.h"
#include "osObjects.h"

q25_req_type * q25_req;

/*----------------------------------------------------------------------------
 *                             q25 task
 *---------------------------------------------------------------------------*/
void q25_task(void   *argument)
{
    rt_err_t rt_st;
    
    osDelay(10);
    gdSpiInit();
    for(;;)
    {
        rt_st = rt_mb_recv(qbid_flash, (rt_uint32_t *)&q25_req, INT32_MAX);
        
        if(RT_EOK == rt_st)
        {
            q25_req->St = Q25_ST_BUSY;
            switch(q25_req->rw_mode)
            {
                case Q25_MODE_READ:
                    gd25qRead(q25_req->Addr, q25_req->Len, q25_req->data);
                    break;
                case Q25_MODE_WRITE:
                    gd25qWrite(q25_req->Addr, q25_req->Len, q25_req->data);
                    break;
                case Q25_MODE_Sector_Erase:
                    gd25qSectorErase(q25_req->Addr);
                    break;
                case Q25_MODE_Block_Erase_32K:
                    gd25qBlockErase(q25_req->Addr);
                    break;
                case Q25_MODE_Chip_Erase:
                    gd25qChipErase();
                    break;
                default:
                    break;
            }
            
            if(q25_req->CallBack)
                q25_req->CallBack();
            
            q25_req->St = Q25_ST_COMP;
        }
    }
}

/*----------------------------------------------------------------------------
 *                             q25 req
 *---------------------------------------------------------------------------*/
void q25_cmd_req(uint32_t q25_par_addr)
{
    rt_mb_send(qbid_flash, q25_par_addr);
}
